package cn.baidu.Servlet;

import cn.baidu.pojo.Room;
import cn.baidu.service.service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/add")   // 访问该类唯一路径
public class add extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");//设置返回数据的编码方式
        resp.setHeader("Content-type", "text/html; charset=utf-8");//设置返回数据的格式为json
        req.setCharacterEncoding("UTF-8");//设置接收参数的编码方式
        String cr = req.getParameter("cr");
        String et = req.getParameter("et");
        String tj = req.getParameter("tj");
        String blrz = req.getParameter("blrz");
        String checkDate = req.getParameter("checkDate");
        String cp = req.getParameter("cp");
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        Date  blrzDate = null;
        Date check = null;
        try {
            blrzDate = format.parse(blrz);
            check = format.parse(checkDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Room room = new Room(0,Integer.parseInt(cr),Integer.parseInt(et),tj,blrzDate,check,cp);
        new service().addRoom(room);
        req.getRequestDispatcher("/houtai").forward(req, resp);

    }


}
